package cloudlearn.eureka.cloudlisten;

import org.springframework.cloud.netflix.eureka.server.event.*;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

/**
 * Project Name: cloud-learn
 * File Name: EurekaListener
 * Package Name: listen
 * Date: 2018/7/3  16:18
 * Copyright (c) 2018, tianyul All Rights Reserved.
 */
@Component
public class EurekaListener {

    /**
     * 服务断线事件
     * @param eurekaInstanceCanceledEvent
     */
    @EventListener
    public void listen(EurekaInstanceCanceledEvent eurekaInstanceCanceledEvent) {
        //服务断线事件
        String appName = eurekaInstanceCanceledEvent.getAppName();
        String serviceId = eurekaInstanceCanceledEvent.getServerId();
        System.out.println(appName);
        System.out.println(serviceId);
    }

    /**
     * 服务注册事件
     * @param eurekaInstanceRegisteredEvent
     */
    @EventListener
    public void listen(EurekaInstanceRegisteredEvent eurekaInstanceRegisteredEvent) {
        System.out.println("*************************************服务注册*************************************");
    }

    /**
     * 服务续约时间
     * @param eurekaInstanceRenewedEvent
     */
    @EventListener
    public void listen(EurekaInstanceRenewedEvent eurekaInstanceRenewedEvent) {
        System.out.println("*************************************服务续约*************************************");
    }

    /**
     * 注册中心启动事件
     * @param eurekaRegistryAvailableEvent
     */
    @EventListener
    public void listen(EurekaRegistryAvailableEvent eurekaRegistryAvailableEvent) {
        System.out.println("*************************************注册中心启动*************************************");
    }

    /**
     * Eureka Server 启动事件
     * @param eurekaServerStartedEvent
     */
    @EventListener
    public void listen(EurekaServerStartedEvent eurekaServerStartedEvent) {
        System.out.println("*************************************Eureka Server 启动*************************************");
    }
}
